Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2656 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
11 changed files with 1481 additions and 1350 deletions
@ -0,0 +1,65 @@
@@ -0,0 +1,65 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision: 2644$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.NRefactory.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory |
||||
{ |
||||
/// <summary>
|
||||
/// Stores the operator precedences for the output visitor.
|
||||
/// </summary>
|
||||
static class OperatorPrecedence |
||||
{ |
||||
static readonly Dictionary<BinaryOperatorType, int> vbDict = MakePrecedenceTable( |
||||
new BinaryOperatorType[] { BinaryOperatorType.Power }, |
||||
new BinaryOperatorType[] { BinaryOperatorType.Multiply, BinaryOperatorType.Divide }, |
||||
new BinaryOperatorType[] { BinaryOperatorType.DivideInteger }, |
||||
new BinaryOperatorType[] { BinaryOperatorType.Modulus }, |
||||
new BinaryOperatorType[] { BinaryOperatorType.Add, BinaryOperatorType.Subtract }, |
||||
new BinaryOperatorType[] { BinaryOperatorType.Concat }, |
||||
new BinaryOperatorType[] { BinaryOperatorType.ShiftLeft, BinaryOperatorType.ShiftRight }, |
||||
new BinaryOperatorType[] { |
||||
BinaryOperatorType.Equality, BinaryOperatorType.InEquality, |
||||
BinaryOperatorType.LessThan, BinaryOperatorType.LessThanOrEqual, |
||||
BinaryOperatorType.GreaterThan, BinaryOperatorType.GreaterThanOrEqual, |
||||
BinaryOperatorType.ReferenceEquality, BinaryOperatorType.ReferenceInequality, |
||||
BinaryOperatorType.Like |
||||
}, |
||||
new BinaryOperatorType[] { BinaryOperatorType.LogicalAnd, BinaryOperatorType.BitwiseAnd }, |
||||
new BinaryOperatorType[] { BinaryOperatorType.LogicalOr, BinaryOperatorType.BitwiseOr }, |
||||
new BinaryOperatorType[] { BinaryOperatorType.ExclusiveOr } |
||||
); |
||||
|
||||
// create a dictionary operator->precedence (higher value = higher precedence)
|
||||
static Dictionary<BinaryOperatorType, int> MakePrecedenceTable(params BinaryOperatorType[][] input) |
||||
{ |
||||
Dictionary<BinaryOperatorType, int> dict = new Dictionary<BinaryOperatorType, int>(); |
||||
for (int i = 0; i < input.Length; i++) { |
||||
foreach (BinaryOperatorType op in input[i]) { |
||||
dict.Add(op, input.Length - i); |
||||
} |
||||
} |
||||
return dict; |
||||
} |
||||
|
||||
public static int ComparePrecedenceVB(BinaryOperatorType op1, BinaryOperatorType op2) |
||||
{ |
||||
int p1 = GetOperatorPrecedence(vbDict, op1); |
||||
int p2 = GetOperatorPrecedence(vbDict, op2); |
||||
return p1.CompareTo(p2); |
||||
} |
||||
|
||||
static int GetOperatorPrecedence(Dictionary<BinaryOperatorType, int> dict, BinaryOperatorType op) |
||||
{ |
||||
int p; |
||||
dict.TryGetValue(op, out p); |
||||
return p; |
||||
} |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue