FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
daScript/src/ast/ast_match.cpp at master · rburkholder/daScript · GitHub
rburkholder
/
daScript
Public
forked from
GaijinEntertainment/daScript
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
daScript
/
src
/
ast
/
ast_match.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
90 lines (81 loc) · 4.1 KB
Breadcrumbs
daScript
/
src
/
ast
/
ast_match.cpp
Copy path
File metadata and controls
90 lines (81 loc) · 4.1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#
include
"
daScript/misc/platform.h
"
#
include
"
daScript/ast/ast_match.h
"
#
include
"
daScript/ast/ast_expressions.h
"
namespace
das
{
//
recognize a==0, a!=0, 0==a, 0!=a
bool
matchEquNequZero
(
const
ExpressionPtr & expr, ExpressionPtr & zeroCond,
bool
& condIfZero ) {
if
( expr->
rtti_isOp2
() ) {
auto
op2 = static_pointer_cast<ExprOp2>(expr);
if
( op2->
op
==
"
==
"
|| op2->
op
==
"
!=
"
) {
condIfZero = op2->
op
==
"
==
"
;
if
(
isZeroConst
(op2->
left
) ) {
zeroCond = op2->
right
;
return
true
;
}
else
if
(
isZeroConst
(op2->
right
) ) {
zeroCond = op2->
left
;
return
true
;
}
}
}
return
false
;
}
bool
isZeroConst
(
const
ExpressionPtr & expr ) {
return
isFloatConst
(expr,
0
.
0f
) ||
isIntOrUIntConst
(expr,
0
) ||
isPtrZero
(expr);
}
bool
isPtrZero
(
const
ExpressionPtr & expr ) {
if
( !expr->
rtti_isConstant
() )
return
false
;
auto
ce = static_pointer_cast<ExprConst>(expr);
switch
( ce->
baseType
) {
case
Type::tPointer:
return
cast<
void
*>::
to
(ce->
value
) ==
nullptr
;
default
:
return
false
;
}
}
bool
isFloatConst
(
const
ExpressionPtr & expr,
float
value ) {
if
( !expr->
rtti_isConstant
() )
return
false
;
auto
ce = static_pointer_cast<ExprConst>(expr);
switch
( ce->
baseType
) {
case
Type::tFloat:
return
cast<
float
>::
to
(ce->
value
) == value;
default
:
return
false
;
}
}
bool
isIntOrUIntConst
(
const
ExpressionPtr & expr,
int64_t
value ) {
if
( !expr->
rtti_isConstant
() )
return
false
;
auto
ce = static_pointer_cast<ExprConst>(expr);
switch
( ce->
baseType
) {
case
Type::tInt:
return
int64_t
( cast<
int32_t
>::
to
(ce->
value
) ) == value;
case
Type::tInt8:
return
int64_t
( cast<
int8_t
>::
to
(ce->
value
) ) == value;
case
Type::tInt16:
return
int64_t
( cast<
int16_t
>::
to
(ce->
value
) ) == value;
case
Type::tInt64:
return
cast<
int64_t
>::
to
(ce->
value
) == value;
case
Type::tUInt:
return
int64_t
( cast<
uint32_t
>::
to
(ce->
value
) ) == value;
case
Type::tBitfield:
return
int64_t
( cast<
uint32_t
>::
to
(ce->
value
) ) == value;
case
Type::tUInt8:
return
int64_t
( cast<
uint8_t
>::
to
(ce->
value
) ) == value;
case
Type::tUInt16:
return
int64_t
( cast<
uint16_t
>::
to
(ce->
value
) ) == value;
case
Type::tUInt64:
return
int64_t
( cast<
uint64_t
>::
to
(ce->
value
) ) == value;
default
:
return
false
;
}
}
bool
isIntConst
(
const
ExpressionPtr & expr,
int64_t
value ) {
if
( !expr->
rtti_isConstant
() )
return
false
;
auto
ce = static_pointer_cast<ExprConst>(expr);
switch
( ce->
baseType
) {
case
Type::tInt:
return
int64_t
( cast<
int32_t
>::
to
(ce->
value
) ) == value;
case
Type::tInt8:
return
int64_t
( cast<
int8_t
>::
to
(ce->
value
) ) == value;
case
Type::tInt16:
return
int64_t
( cast<
int16_t
>::
to
(ce->
value
) ) == value;
case
Type::tInt64:
return
cast<
int64_t
>::
to
(ce->
value
) == value;
default
:
return
false
;
}
}
bool
isUIntConst
(
const
ExpressionPtr & expr,
uint64_t
value ) {
if
( !expr->
rtti_isConstant
() )
return
false
;
auto
ce = static_pointer_cast<ExprConst>(expr);
switch
( ce->
baseType
) {
case
Type::tUInt:
return
uint64_t
( cast<
uint32_t
>::
to
(ce->
value
) ) == value;
case
Type::tBitfield:
return
uint64_t
( cast<
uint32_t
>::
to
(ce->
value
) ) == value;
case
Type::tUInt8:
return
uint64_t
( cast<
uint8_t
>::
to
(ce->
value
) ) == value;
case
Type::tUInt16:
return
uint64_t
( cast<
uint16_t
>::
to
(ce->
value
) ) == value;
case
Type::tUInt64:
return
cast<
uint64_t
>::
to
(ce->
value
) == value;
default
:
return
false
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL