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