CaseNode.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #include "Backend.h"
  6. int
  7. DefaultComparer<CaseNode *>::Compare(CaseNode* caseNode1, CaseNode* caseNode2)
  8. {
  9. int caseVal1 = caseNode1->GetUpperBoundIntConst();
  10. int caseVal2 = caseNode2->GetUpperBoundIntConst();
  11. uint32 caseOffset1 = caseNode1->GetOffset();
  12. uint32 caseOffset2 = caseNode2->GetOffset();
  13. if (caseVal1 == caseVal2)
  14. {
  15. return caseOffset1 - caseOffset2;
  16. }
  17. if (caseVal1 > caseVal2) return 1;
  18. return -1;
  19. }
  20. bool
  21. DefaultComparer<CaseNode *>::Equals(CaseNode * caseNode1, CaseNode* caseNode2)
  22. {
  23. if(caseNode1->IsUpperBoundIntConst() && caseNode2->IsUpperBoundIntConst())
  24. {
  25. int caseVal1 = caseNode1->GetUpperBoundIntConst();
  26. int caseVal2 = caseNode2->GetUpperBoundIntConst();
  27. return caseVal1 == caseVal2;
  28. }
  29. else if(caseNode1->IsUpperBoundStrConst() && caseNode2->IsUpperBoundStrConst())
  30. {
  31. JITJavascriptString * caseVal1 = caseNode1->GetUpperBoundStrConst();
  32. JITJavascriptString * caseVal2 = caseNode2->GetUpperBoundStrConst();
  33. return JITJavascriptString::Equals(caseVal1, caseVal2);
  34. }
  35. else
  36. {
  37. AssertMsg(false, "Should not reach here. CaseNodes should store only string or integer case values");
  38. return false;
  39. }
  40. }
  41. uint
  42. DefaultComparer<CaseNode *>::GetHashCode(CaseNode* caseNode)
  43. {
  44. return (uint)caseNode->GetUpperBoundIntConst();
  45. }