| 1 | |
|---|
| 2 | class OperatorSpecs |
|---|
| 3 | |
|---|
| 4 | # TODO: move the binary op and unary op specs here |
|---|
| 5 | |
|---|
| 6 | shared |
|---|
| 7 | var _rightAssoc = { # CC: change to Set |
|---|
| 8 | 'STARSTAR': true, |
|---|
| 9 | 'ASSIGN': true, |
|---|
| 10 | 'PLUS_EQUALS': true, |
|---|
| 11 | 'MINUS_EQUALS': true, |
|---|
| 12 | 'STAR_EQUALS': true, |
|---|
| 13 | 'SLASH_EQUALS': true, |
|---|
| 14 | 'PERCENT_EQUALS': true, |
|---|
| 15 | 'AMPERSAND_EQUALS': true, |
|---|
| 16 | 'VERTICAL_BAR_EQUALS': true, |
|---|
| 17 | 'CARET_EQUALS': true, |
|---|
| 18 | 'DOUBLE_LT_EQUALS': true, |
|---|
| 19 | 'DOUBLE_GT_EQUALS': true, |
|---|
| 20 | } |
|---|
| 21 | |
|---|
| 22 | get rightAssoc as Dictionary<of String, bool> |
|---|
| 23 | .processTable |
|---|
| 24 | return _rightAssoc |
|---|
| 25 | |
|---|
| 26 | # reference: http://msdn2.microsoft.com/en-us/library/ms229032.aspx |
|---|
| 27 | var _table = [ |
|---|
| 28 | 'u, , , ToXxx or FromXxx, op_Implicit', |
|---|
| 29 | 'u, , , ToXxx or FromXxx, op_Explicit', |
|---|
| 30 | 'b, +, +, Add, op_Addition', |
|---|
| 31 | 'b, -, -, Subtract, op_Subtraction', |
|---|
| 32 | 'b, *, *, Multiply, op_Multiply', |
|---|
| 33 | 'br, **, , , ', |
|---|
| 34 | 'b, /, /, Divide, op_Division', |
|---|
| 35 | 'b, //, , IntegerDivide, op_IntegerDivision', |
|---|
| 36 | 'b, %, %, Mod, op_Modulus', |
|---|
| 37 | 'b, ^, ^, Xor, op_ExclusiveOr', |
|---|
| 38 | 'b, &, &, BitwiseAnd, op_BitwiseAnd', |
|---|
| 39 | 'b, |, |, BitwiseOr, op_BitwiseOr', |
|---|
| 40 | 'b, and, &&, And, op_LogicalAnd', |
|---|
| 41 | 'b, or, ||, Or, op_LogicalOr', |
|---|
| 42 | 'br, =, =, Assign, op_Assign', |
|---|
| 43 | 'b, <<, <<, LeftShift, op_LeftShift', |
|---|
| 44 | 'b, >>, >>, RightShift, op_RightShift', |
|---|
| 45 | 'b, , , LeftShift, op_SignedRightShift', |
|---|
| 46 | 'b, , , RightShift, op_UnsignedRightShift', |
|---|
| 47 | 'b, ==, ==, Equals, op_Equality', |
|---|
| 48 | 'b, >, >, CompareTo, op_GreaterThan', |
|---|
| 49 | 'b, <, <, CompareTo, op_LessThan', |
|---|
| 50 | 'b, <>, !=, Equals, op_Inequality', |
|---|
| 51 | 'b, >=, >=, CompareTo, op_GreaterThanOrEqual', |
|---|
| 52 | 'b, <=, <=, CompareTo, op_LessThanOrEqual', |
|---|
| 53 | 'br, *=, *=, Multiply, op_MultiplicationAssignment', |
|---|
| 54 | 'br, -=, -=, Subtract, op_SubtractionAssignment', |
|---|
| 55 | 'br, ^=, ^=, Xor, op_ExclusiveOrAssignment', |
|---|
| 56 | 'br, <<=, <<=, LeftShift, op_LeftShiftAssignment', |
|---|
| 57 | 'br, %=, %=, Mod, op_ModulusAssignment', |
|---|
| 58 | 'br, +=, +=, Add, op_AdditionAssignment', |
|---|
| 59 | 'br, &=, &=, BitwiseAnd, op_BitwiseAndAssignment', |
|---|
| 60 | 'br, |=, |=, BitwiseOr, op_BitwiseOrAssignment', |
|---|
| 61 | 'br, /=, /=, Divide, op_DivisionAssignment', |
|---|
| 62 | 'br, //=, , IntegerDivide, op_IntegerDivide', |
|---|
| 63 | 'u, , --, Decrement, op_Decrement', |
|---|
| 64 | 'u, , ++, Increment, op_Increment', |
|---|
| 65 | 'u, -, -, Negate, op_UnaryNegation', |
|---|
| 66 | 'u, +, +, Plus, op_UnaryPlus', |
|---|
| 67 | 'u, ~, ~, OnesComplement, op_OnesComplement', |
|---|
| 68 | ] |
|---|
| 69 | |
|---|
| 70 | var _opSpecs = List<of OpSpec>() |
|---|
| 71 | var _binaryOpSpecsByCobraText = Dictionary<of String, OpSpec>() |
|---|
| 72 | var _unaryOpSpecsByCobraText = Dictionary<of String, OpSpec>() |
|---|
| 73 | |
|---|
| 74 | get opSpecs as List<of OpSpec> |
|---|
| 75 | .processTable |
|---|
| 76 | return _opSpecs |
|---|
| 77 | |
|---|
| 78 | get binaryOpSpecsByCobraText as Dictionary<of String, OpSpec> |
|---|
| 79 | .processTable |
|---|
| 80 | return _binaryOpSpecsByCobraText |
|---|
| 81 | |
|---|
| 82 | get unaryOpSpecsByCobraText as Dictionary<of String, OpSpec> |
|---|
| 83 | .processTable |
|---|
| 84 | return _unaryOpSpecsByCobraText |
|---|
| 85 | |
|---|
| 86 | var _didProcessTable = false |
|---|
| 87 | |
|---|
| 88 | def processTable |
|---|
| 89 | if _didProcessTable |
|---|
| 90 | return |
|---|
| 91 | for row in _table |
|---|
| 92 | parts = row.split(c',') |
|---|
| 93 | assert parts.length == 5, row |
|---|
| 94 | for i = 0 .. parts.length |
|---|
| 95 | parts[i] = parts[i].trim |
|---|
| 96 | spec = OpSpec(parts) |
|---|
| 97 | _opSpecs.add(spec) |
|---|
| 98 | if spec.cobraText <> '' |
|---|
| 99 | if spec.isBinary |
|---|
| 100 | _binaryOpSpecsByCobraText.add(spec.cobraText, spec) |
|---|
| 101 | if spec.isUnary |
|---|
| 102 | _unaryOpSpecsByCobraText.add(spec.cobraText, spec) |
|---|
| 103 | _didProcessTable = true |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | class OpSpec |
|---|
| 107 | |
|---|
| 108 | var _isBinary as bool |
|---|
| 109 | var _isRightAssoc as bool |
|---|
| 110 | var _cobraText as String |
|---|
| 111 | var _sharpText as String |
|---|
| 112 | var _methodName as String |
|---|
| 113 | var _opMethodName as String |
|---|
| 114 | |
|---|
| 115 | cue init(specParts as System.Collections.IList) |
|---|
| 116 | base.init |
|---|
| 117 | _isBinary = specParts[0] to String in ['b', 'br'] |
|---|
| 118 | _isRightAssoc = specParts[0] == 'br' |
|---|
| 119 | _cobraText = specParts[1] to String |
|---|
| 120 | _sharpText = specParts[2] to String |
|---|
| 121 | _methodName = specParts[3] to String |
|---|
| 122 | _opMethodName = specParts[4] to String |
|---|
| 123 | |
|---|
| 124 | get isBinary from var |
|---|
| 125 | |
|---|
| 126 | get isUnary as bool |
|---|
| 127 | return not _isBinary |
|---|
| 128 | |
|---|
| 129 | get isRightAssoc from var |
|---|
| 130 | |
|---|
| 131 | get cobraText from var |
|---|
| 132 | |
|---|
| 133 | get sharpText from var |
|---|
| 134 | |
|---|
| 135 | get methodName from var |
|---|
| 136 | |
|---|
| 137 | get opMethodName from var |
|---|